package com.woniuxy.patrol.controller;

import com.woniuxy.common.utils.ResponseUtil;
import com.woniuxy.patrol.pojo.PatrolPoint;
import com.woniuxy.patrol.service.PatrolPointService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * 巡更点位控制器（对应《巡更demo.docx》3.1节巡更点位管理功能）
 */
@RestController
@RequestMapping("/patrol/point")
public class PatrolPointController {

    @Resource
    private PatrolPointService patrolPointService;

    /**
     * 按社区查询巡更点位
     */
    @GetMapping("/list")
    public ResponseUtil getByCommunity(@RequestParam Long communityId) {
        return patrolPointService.getByCommunityId(communityId);
    }

    /**
     * 添加巡更点
     */
    @PostMapping("/add")
    public ResponseUtil addPoint(@RequestBody PatrolPoint patrolPoint) {
        return patrolPointService.addPoint(patrolPoint);
    }

    /**
     * 编辑巡更点
     */
    @PostMapping("/update")
    public ResponseUtil updatePoint(@RequestBody PatrolPoint patrolPoint) {
        return patrolPointService.updatePoint(patrolPoint);
    }

    /**
     * 删除巡更点
     */
    @GetMapping("/delete")
    public ResponseUtil deletePoint(@RequestParam Long pointId) {
        return patrolPointService.deletePoint(pointId);
    }

    /**
     * 按路线查询点位
     */
    @GetMapping("/byRoute")
    public ResponseUtil getByRoute(@RequestParam Long routeId) {
        return patrolPointService.getByRouteId(routeId);
    }

    /**
     * 校验点位位置
     */
    @GetMapping("/validateLocation")
    public ResponseUtil validateLocation(
            @RequestParam Long pointId,
            @RequestParam Double userLatitude,
            @RequestParam Double userLongitude) {

        System.out.println("pointId: " + pointId + ", latitude: " + userLatitude + ", longitude: " + userLongitude);
        Map<String, Object> result = patrolPointService.validateLocation(pointId, userLatitude, userLongitude);
        // 打印返回结果
        System.out.println("返回结果: " + result);
        return ResponseUtil.success(result);
    }

}
